package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.ClsService;

@RestController
@RequestMapping("/api/class")
public class ClsController {

    private ClsService clsService;

    @Autowired
    public void autowiredService(ClsService clsService){
        this.clsService = clsService;
    }

    @RequestMapping("/{cid}")
    public Result getCls(@PathVariable int cid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getCls(cid, request, response);
    }

    /**
     * 获取class内的所有User
     * @param cid class id
     */
    @RequestMapping("/user/{cid}")
    public Result getClassUsers(@PathVariable int cid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getClassUsers(cid, request, response);
    }

    /**
     * 获取user所在的class
     * @param uid user id
     */
    @RequestMapping("/user/class/{uid}")
    public Result getUserClasses(@PathVariable int uid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getUserClasses(uid, request, response);
    }

    /**
     * 向class内添加user
     */
    @RequestMapping("/user/add/{cid}")
    public Result addClassUser(@RequestParam int uid, @PathVariable int cid,
                               HttpServletRequest request, HttpServletResponse response){
        return clsService.addClassUser(uid, cid, request, response);
    }

    /**
     * 获取class内的所有teacher
     * @param cid class id
     */
    @RequestMapping("/teacher/{cid}")
    public Result getClassTeachers(@PathVariable int cid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getClassTeachers(cid, request, response);
    }

    /**
     * 获取teacher所在的class
     * @param tid teacher id
     */
    @RequestMapping("/teacher/class/{tid}")
    public Result getTeacherClasses(@PathVariable int tid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getTeacherClasses(tid, request, response);
    }

    /**
     * 向class内添加teacher
     * @param data teacher json
     */
    @RequestMapping("/teacher/add")
    public Result addClassTeacher(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return clsService.addClassTeacher(data, request ,response);
    }

    /**
     * 获取class内的所有subject
     * @param cid class id
     */
    @RequestMapping("/subject/{cid}")
    public Result getClassSubject(@PathVariable int cid, HttpServletRequest request, HttpServletResponse response){
        return clsService.getClassSubjects(cid, request, response);
    }

    /**
     * 向class内添加subject
     * @param data subject json
     */
    @RequestMapping("/subject/add")
    public Result addClassSubject(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return clsService.addClassSubject(data, request, response);
    }

    /**
     * 添加class
     * @param data class json
     */
    @RequestMapping("/add")
    public Result addClass(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return clsService.addCls(data, request, response);
    }

    /**
     * 修改class
     * @param data class json
     */
    @RequestMapping("/update")
    public Result updateClass(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return clsService.updateCls(data, request, response);
    }

    @RequestMapping("/all")
    public Result updateClass(HttpServletRequest request, HttpServletResponse response){
        return clsService.getAllClass(request, response);
    }

    @RequestMapping("/delete/{cid}")
    public Result deleteCls(@PathVariable int cid, HttpServletRequest request, HttpServletResponse response){
        return clsService.deleteCls(cid, request, response);
    }

}
